package com.apes.fn.serveControl.serverParentPackage;

import com.alibaba.fastjson.JSONObject;
import com.apes.framework.query.SqlService;
import com.apestech.framework.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Creator: zouyc
 * CreateDate: 2021-03-31 16:53
 * Description:
 **/
public class abstractPubQuery extends  PControlService{
    @Autowired
    SqlService sqlService;

    private String address;
    private com.apestech.framework.json.JSONObject param;
    /**
     * 执行器默认需要传入
     * @param address
     * @param param
     */
    public abstractPubQuery(String address,JSONObject param){
        checkAndRemove(param);
        this.address = address;
        this.param = new com.apestech.framework.json.JSONObject(param);
    }
    /**
     * 执行入口
     * 返回类型两种：
     * 返回JSONARRAY
     * 返回分页对象
     * @return
     */
    public Object excute(){
        JSONArray result = sqlService.queryId(address,param);
        return null;
    }

    /**
     * 验证参数是否有问题
     * 1.分页数据判断
     * 2.有几个参数得过滤：customAction，noSum，queryid，customQuery
     * @param param
     */
    private void checkAndRemove(JSONObject param){
        if(param.get("customAction") != null) param.remove("customAction");
        if(param.get("noSum") != null) param.remove("noSum");
        if(param.get("queryid") != null) param.remove("queryid");
        if(param.get("customQuery") != null) param.remove("customQuery");
        if(param.get("page") != null){
            if(param.getInteger("size") >= 1000) throw new RuntimeException("分页数据不能大于1000");
        }
    }
}